package s08.ch10.homework;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

public class Suv extends Car {
	private Date yearOfProduction;

	public Suv(String color, BigDecimal price, Date yearOfProduction) {
		super(color, price);
		setYearOfProduction(yearOfProduction);
	}

	public Date getYearOfProduction() {
		return yearOfProduction;
	}

	public void setYearOfProduction(Date yearOfProduction) {
		this.yearOfProduction = yearOfProduction;
	}

	protected Long getYear() {
		Date today = new Date();
		Long seconds = today.getTime() - getYearOfProduction().getTime();
		Long years = (seconds / (1000 * 60 * 60 * 24)) / 365;
		return years;
	}

	public BigDecimal getDiscountedPrice() {
		if (getYear() <= 10) {
			BigDecimal cena = getPrice();
			return cena;
		} else {
			Double discountPercent = 0.2;
			BigDecimal decimalDiscountPercent = new BigDecimal(
					Double.toString(discountPercent));
			BigDecimal decimalSubtotal = getPrice();
			decimalSubtotal = decimalSubtotal
					.setScale(-1, RoundingMode.HALF_UP);
			BigDecimal discountAmount = decimalSubtotal
					.multiply(decimalDiscountPercent);
			BigDecimal discount = decimalSubtotal.subtract(discountAmount);
			return discount;
		}

	}
}
